package steampunk.geom;

import steampunk.art.Art;
import steampunk.art.PointArt;
import steampunk.utils.Mutil;

public class PointGeom extends BaseGeom {

	private double x = 0;
	private double y = 0;
	private double lx = 0;
	private double ly = 0;
	private double vx = 0;
	private double vy = 0;
	
	public double getVelX() {
		return vx;
	}
	public double getVelY() {
		return vy;
	}
	public void setVelX(double d) {
		this.vx = d;
	}
	public void setVelY(double d) {
		this.vy = d;
	}
	public void accelerate(double x, double y) {
		this.vx += x;
		this.vy += y;
	}
	public void setVelocity(double x, double y) {
		this.vx = x;
		this.vy = y;
	}
	
	public void setX(double x) {
		this.x = x;
		this.lx = x;
	}
	public void setY(double y) {
		this.y = y;
		this.ly = y;
	}
	public void modX(double x) {
		this.x += x;
	}
	public void modY(double y) {
		this.y += y;
	}
	public double getX() {
		return x;
	}
	public double getY() {
		return y;
	}
	
	public int ix() {
		return (int)x;
	}
	public int iy() {
		return (int)y;
	}
	
	public double left() {
		return x;
	}
	public double right() {
		return x;
	}
	public double top() {
		return y;
	}
	public double bottom() {
		return y;
	}
	
	public void left(double d) {
		this.x = d;
	}
	public void right(double d) {
		this.x = d;
	}
	public void top(double d) {
		this.y = d;
	}
	public void bottom(double d) {
		this.y = d;
	}
	
	public double lastX() {
		return lx;
	}
	public double lastY() {
		return ly;
	}
	
	public void moveBy(double x, double y) {
		this.x += x;
		this.y += y;
	}
	public void moveTo(double x, double y) {
		this.x = x;
		this.y = y;
	}
	
	public void updatePosition(double seconds) {
		this.lx = x;
		this.ly = y;
		x += vx * seconds;
		y += vy * seconds;
	}
	
	public void update(double seconds) {
		updatePosition(seconds);
	}
	@Override
	public boolean containsPoint(double x, double y) {
		return x == getX() && y == getY();
	}
	@Override
	public boolean intersects(Intersectable other) {
		return other.containsPoint(getX(), getY());
	}
	@Override
	public boolean intersectsCircle(double x, double y, double radius) {
		// just distance formula squared (which is just pythagorean theorum)
		return (getX()-x)*(getX()-x) + (getY()-y)*(getY()-y) <= radius*radius; 
	}
	@Override
	public boolean intersectsLine(double x1, double y1, double x2, double y2) {
		return Mutil.pointOnLine(x1, y1, x2, y2, getX(), getY(), 1);
	}
	@Override
	public boolean intersectsRect(int x, int y, int w, int h) {
		if (right() < x)
			return false;
		if (left() > x + w)
			return false;
		if (bottom() < y)
			return false;
		if (top() > y + h)
			return false;
		return true;
	}
	
	public Art getWireArt() {
		return new PointArt(this);
	}
}
